# -*- coding: utf-8 -*-
from django.shortcuts import render_to_response
from django.template import RequestContext

def render_to(template_path):
    """
    Expect the dict from view. Render returned dict with
    RequestContext.
    """

    def decorator(func):
        def wrapper(request, *args, **kwargs):
            output = func(request, *args, **kwargs)
            if not isinstance(output, dict):
                return output
            kwargs = {'context_instance': RequestContext(request)}
            if 'MIME_TYPE' in output:
                kwargs['mimetype'] = output['MIME_TYPE']
            return render_to_response(template_path, output, **kwargs)
        wrapper.__name__ = func.__name__     # in order to get in
        wrapper.__module__ = func.__module__ # show_urls real view name
        return wrapper
    return decorator

